package com.find.memories.photoviewer;

import android.graphics.Point;
import android.graphics.RectF;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

import com.find.memories.R;
import com.find.memories.photoviewer.ThumbnailView.DragReachTheWallListener;

/**
 * ThumbnailView Body를 Control할 수 있는 class.
 * @author Jang
 *
 */
public class PhotoViewerThumbnailView  implements PhotoViewerBodyInterface {
	
	private ThumbnailView mImageView;
	private String mImagePath = null;
	private SlideStateListener mSlideStateListener;
	
	public PhotoViewerThumbnailView(View view) {
		if (view != null)
			init(view);
	}

	void init(View view) {
		mImageView = (ThumbnailView) view.findViewById(R.id.photo_viewer_body_imageview);

		mImageView.setDragReachTheWallListener(new DragReachTheWallListener() {
            
            @Override
            public void availableSlide(int which) {
                // TODO Auto-generated method stub
                if (mSlideStateListener != null) {
                    mSlideStateListener.SlideState(which);
                }
            }
        });
	}
	
	@Override
    public void destroyItem() {
        if (mImageView != null) {
            if (mImageView.getDrawable() != null) {
                mImageView.getDrawable().setCallback(null);
            }
            mImageView.setDragReachTheWallListener(null);
            mImageView.setBackgroundDrawable(null);
            mImageView.setImageDrawable(null);
            mImageView = null;
        }
    }
	
	public RectF getImageViewRect() {
		RectF rect = new RectF();
		if (mImageView != null)
			rect.set((int)mImageView.getLeft(), (int)mImageView.getTop(), (int)mImageView.getLeft()+mImageView.getWidth(), (int)mImageView.getTop()+mImageView.getHeight());
		return rect;
	}

	@Override
	public ImageView getImageView() {
		
		return mImageView;
	}

	@Override
	public void setZoomMode(boolean enable, int maxZoom, Point point) {
		
		if (mImageView != null)
			mImageView.setZoomMode(enable, maxZoom, point);
	}

	@Override
	public boolean isZoomMode() {
		
		boolean result = false;
		if (mImageView != null) {
			result = mImageView.isZoomMode();
		}
		return result;
	}
	
    @Override
    public int[] getImagePosition() {
        
        return null;
    }

    @Override
    public void setImagePosition(int[] position) {
        
        
    }

    @Override
    public boolean isMaxDoubleTapZoom() {
        
        if (mImageView != null) {
            return mImageView.isMaxTapZoom();
        }
        return false;
    }

    @Override
    public float getZoomScale() {
        float scale = 1.0f;
        if (mImageView != null) {
            scale = mImageView.getCurrentScale();
        }
        return scale;
    }

    @Override
    public boolean sendTouchEvent(MotionEvent ev) {
        
        if (mImageView != null) {
            return mImageView.getTouchEvent(ev);
        }
        return false;
    }
    
    @Override
    public String getImagePath() {
        return mImagePath;
    }

    @Override
    public void setImagePath(String path) {
        mImagePath = path;
    }

    @Override
    public void setSlideStateListener(SlideStateListener listener) {
        mSlideStateListener = listener;
    }
}
